<?php
/**
 * @name SampleModel
 * @desc sample数据获取类, 可以访问数据库，文件，其它系统等
 * @author root
 */
class GroupModel
{
    public function __construct()
    {
        $this->db = Yaf_Registry::get('db');
    }

    public function selectGroupInfo()
    {
        $sql = "select * from `group` ";
        return $this->db->query($sql);
    }
    public function selectLastId()
    {
        $sql = "select * from `group` ";
        return $this->db->lastInsertId($sql);
    }
    public function getGroupInfo($start,$everyPage)
    {
        $sql = "select * from `group` limit {$start},{$everyPage}";
        return $this->db->query($sql);
    }
    public function getAllCount()
    {
        $sql="select count(*) as `rows` from `group` ";
        return $this->db->query($sql);
    }
    public function del($id)
    {
        $sql = "delete from `group` where group_id='{$id}' ";
        return $this->db->query($sql);
    }

    public function add($info)
    {
        $sql="insert into `group`(`name`,`level`) values('{$info['name']}','{$info["level"]}')";
        //return $this->db->lastInsertId($sql);
        return $this->db->query($sql);
    }
    public function addId($b,$info)
    {
        $sql="insert into `group_authority`(`group_id`,`authority_id`) values('{$b}','{$info}')";
        return $this->db->query($sql);
    }
    public function edit($info, $id)
    {
        $sql = "update `group` set `name`='{$info['name']}', `level`='{$info['level']}' WHERE `group_id`='{$id}'";
        return $this->db->query($sql);
    }
    public function editID($info,$id)
    {
        $sql = "update `group_authority` set `authority_id`='{$info}' WHERE `group_id`='{$id}'";
        return $this->db->query($sql);
    }



    public function getGroupAuthorityID($group_id)
    {
        $sql="select `authority`.`authority_id`, `authority`.`name` from `group_authority`,`authority` where `group_authority`.`authority_id` = `authority`.`authority_id` and `group_authority`.`group_id` = $group_id";
        $authority_sql = "insert into `group_authority` (`group_id`,`authority_id`) values(null,'{$info['authority_id']}')";
        return $this->db->query($sql);
        return $this->db->query($authority_sql);
    }
}
?>
